package cn.com.aiton.common.utils;

import cn.com.aiton.common.model.ServiceResult;
import cn.com.aiton.common.model.gbt209992007.GbtScheduleDomain;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

/**
 * json转换工具类
 * Created by Administrator on 2016/11/29.
 */
public class JsonToScheduleListUtil {
    private static final Logger LOG =
            LoggerFactory.getLogger(JsonToScheduleListUtil.class);
    private static final ObjectMapper objectMapper = new ObjectMapper();
    public static ServiceResult<List<GbtScheduleDomain> > scheduleList(String json) {
        ServiceResult<List<GbtScheduleDomain> > map = new ServiceResult<>();
        try {
            List<GbtScheduleDomain> listll = objectMapper.readValue(json, new TypeReference<List<GbtScheduleDomain>>(){});
//            JSONArray array = new JSONArray(json);
//            List<GbtScheduleDomain> list = new ArrayList<>();
//            for(int i=0;i<array.length();i++){
//                JSONObject object = array.getJSONObject(i);
//                GbtScheduleCommand command = new GbtScheduleCommand();
//                command.setId(object.getLong("id"));
//                command.setEventId(object.getLong("eventId"));
//                command.setBeginHour(object.getInt("beginHour"));
//                command.setBeginMinute(object.getInt("beginMinute"));
//                command.setControlMode(object.getInt("controlMode"));
//                command.setTimePatternId(object.getInt("timePatternId"));
//                command.setAuxOut(object.getInt("auxOut"));
//                command.setSpecialOut(object.getInt("specialOut"));
//                list.add(command);
//            }

            map.setSuccess(true);
            map.setObject(listll);
            return map;
        } catch (Exception e) {
            LOG.error(e.getMessage(), e);
            map.setMessage("数据转换出错");
            map.setSuccess(false);
            return map;
        }
    }

}
